<?php
$start=microtime();
set_time_limit(0);
//path to system folder
$path=substr(dirname(__FILE__), 0, strrpos(dirname(__FILE__), 'expressionengine'));
//define basepath to access database config file
define('BASEPATH', str_replace("\\", "/", $path.'codeigniter/system/'));

require 'loader.php';
//getting db info
require $path.'expressionengine/config/database.php';

define('HOST', $db['expressionengine']['hostname']);
define('USERNAME', $db['expressionengine']['username']);
define('PASS', $db['expressionengine']['password']);
define('DBNAME', $db['expressionengine']['database']);
define('DBPREFIX', $db['expressionengine']['dbprefix']);

echo '<pre>';
$db=Db::getInstance();

/*
 * getting campain data
 */

$campaigns=$db->where(array("active"=>"1"))->select(DBPREFIX."spider_campaign");
foreach ($campaigns as $campaign){
    //print_r($campaign);
    $apis=unserialize($campaign['api']);
    $keyWords=explode("\n", $campaign['keyword']);
    foreach ($apis as $api){
        $fields=$db->where(array("campainId"=>$campaign['campainId'], "apiName"=>$api))->select("exp_spider_fields");
        $fields=unserialize($fields[0]["fields"]);
        $apiInfo=$db->where(array("campainId"=>$campaign['campainId']))->select("exp_spider_$api");
        //print_r($apiInfo);
        
        $data=new $api($keyWords, $apiInfo);
        var_dump($data->getData());
        
    }
    
}


$end=microtime();
echo 'Execution time: '.($end-$start);

